home *** CD-ROM | disk | FTP | other *** search
/ Scene Storm / Scene Storm - Volume 1.iso / coding / c / amiexpress / source / doors / vault / vault.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-12  |  4.3 KB  |  204 lines

  1. #include <exec/exec.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include "dh1:source/doors/romconf/doorheader.h"
  5. #include "dh0:code/aelib/ae_pragmas.h"
  6.  
  7. char path[200];
  8. char VaultCfg[200];
  9. extern struct Library *AEBase;
  10. #define gu getuserstring
  11. #define pu putuserstring
  12. #define hk hotkey
  13. #define pm prompt
  14. #define sm sendmessage
  15. char name[50];
  16. char Password[6][80];
  17. int Security = 0;
  18. int VaultLevel =0;
  19. char temp[100];
  20. int tempsecure=0;
  21. void InitPass(void);
  22. void ShowIntro(void);
  23. int GetPass(int num);
  24. int Secure(char *s);
  25. int GetVaultLevel(void);
  26. void InitVault(void);
  27. void LastCommand(void);
  28. void end(void);
  29. int Verbose=FALSE;
  30. main(int argc,char *argv[])
  31. {
  32.   register int i;
  33.   if(argc!=2)
  34.   {
  35.     printf("\n");
  36.     printf("Vault version 1.1 , written by Joseph Hodge\n");
  37.     printf("This is a product of the /X Developement Team - The Silent Achievers\n");
  38.     printf("This is a (XIM) for AmiExpress 2.1+\n");
  39.     printf("\n");
  40.     exit(0);
  41.   }
  42.   Register(argv[1][0]-'0');
  43.   strcpy(path,argv[0]);
  44.   i=strlen(path)-1;
  45.   while(i)
  46.   {
  47.     if(path[i]==':' || path[i]=='/') {path[i+1]='\0'; break; }
  48.     i--;
  49.   }
  50.   sprintf(VaultCfg,"%sVault.cfg",path);
  51.   if(!TLock(VaultCfg))
  52.      InitVault();
  53.   VaultLevel=GetVaultLevel();
  54.   gu(temp,DT_SECSTATUS);
  55.   Security=atoi(temp);
  56.   if(Security<VaultLevel) { ShutDown(); end(); }
  57.   if(Security>VaultLevel) { sprintf(temp,"%d",VaultLevel); pu(temp,DT_SECSTATUS); }
  58.   gu(name,DT_NAME); strupr(name);
  59.   if(!Secure(name)) { sm("",1); ShutDown(); end(); }
  60.   sprintf(temp,"%d",tempsecure);
  61.   pu(temp,DT_SECSTATUS);
  62.   sm("",1);
  63.   ShutDown();
  64.   end();
  65.  
  66. }
  67.  
  68. void end(void)
  69. {
  70.   exit(0);
  71. }
  72. void LastCommand(void)
  73. {
  74. }
  75. void InitVault(void)
  76. {
  77.    FILE *fi;
  78.    fi=fopen(VaultCfg,"w");
  79.    fprintf(fi,"VaultLevel 200\n");
  80.    fclose(fi);
  81. }
  82. int GetVaultLevel(void)
  83. {
  84.    FILE *fi;
  85.    char temp[100];
  86.    
  87.    fi=fopen(VaultCfg,"r");
  88.    if(fi==NULL) return(200);
  89.    while(fgets(temp,80,fi)!=NULL)
  90.    {
  91.      strupr(temp);
  92.      if(!strnicmp(temp,"VERBOSE",7)) Verbose=TRUE;
  93.      if(!strnicmp(temp,"VaultLevel ",11))
  94.      {
  95.        fclose(fi);
  96.        return(atoi(&temp[11]));
  97.      }
  98.    }
  99.    fclose(fi);
  100.    return(200);
  101. }
  102.  
  103. int Secure(char *s)
  104. {
  105.   FILE *fi;
  106.   
  107.   BOOL found=FALSE;
  108.   register int i;
  109.   register int j;
  110.   BOOL gotpass=FALSE;
  111.   InitPass();
  112.   fi=fopen(VaultCfg,"r");
  113.   if(fi==NULL) return(0);
  114.   i=0;
  115.   while(fgets(temp,80,fi)!=NULL)
  116.   {
  117.     StripReturn(temp); strupr(temp);
  118.     if(!strcmp(temp,s))
  119.     {
  120.        found=TRUE;
  121.        while(fgets(temp,80,fi)!=NULL)
  122.        {
  123.          if(gotpass && temp[0]!='#') break;
  124.          StripReturn(temp);
  125.          strupr(temp);
  126.          if(!strnicmp(temp,"Access ",7))
  127.          {
  128.            tempsecure=atoi(&temp[7]);
  129.          }
  130.          if(temp[0]=='#' && i<5)
  131.          {
  132.            gotpass=TRUE;
  133.            strcpy(Password[i],&temp[2]);
  134.            i++; 
  135.          }
  136.        }
  137.        fclose(fi);
  138.        break;
  139.     }
  140.   }
  141.   if(!found) { fclose(fi); return(0); }
  142.   ShowIntro();
  143.   j=0;
  144.   while(j<i)
  145.   {
  146.      if(!GetPass(j)) { sm("",1); return(0);}
  147.      sm("",1);
  148.      j++;
  149.   }
  150.   return(1);
  151.          
  152. }     
  153.  
  154. int GetPass(int num)
  155. {
  156.    char Temp[100];
  157.    register int i;
  158.    register int j;
  159.    char pass[200];
  160.  i=3;
  161.    if(Password[num][0]=='\0') return(1);
  162.  while(i)
  163.  {
  164.    sprintf(Temp,"Vault password (%d) >",num+1);
  165.    sm("",1);
  166.    sm(Temp,0);
  167.    strcpy(Temp,Password[num]);
  168.    j=0;
  169.    do
  170.    {
  171.      hk("",Temp);
  172.      
  173.      if(Temp[0]=='\b')
  174.      {
  175.         if(j==0) continue;
  176.         sm("\b \b",0); j--; continue;
  177.      }
  178. strupr(Temp);
  179.      if(Temp[0]!=13 && Temp[0]!=12) {pass[j]=Temp[0]; sm("X",0); j++;}
  180.    }
  181.    while(Temp[0]!=13 && Temp[0]!=12 && j<30);
  182.    pass[j]='\0';
  183.    if(!strcmp(pass,Password[num])) return(1);
  184.    sm("",1);
  185.    i--;
  186.  }
  187.  return(0);
  188. }
  189. void ShowIntro(void)
  190. {
  191.   if(!Verbose) return;
  192.   sm("",1);
  193. sm(" .--------------------------------------------------------------------------.",1);
  194. sm(" |            Ami-Express Vault Version 1.1 Written by ByteMaster           |",1);
  195. sm(" |                /X Development Team - The Silent Achievers                |",1);
  196. sm(" `--------------------------------------------------------------------------'",1);
  197.  sm("",1);
  198. }
  199. void InitPass(void)
  200. {
  201.   register int i=0;
  202.   while(i<5) { strcpy(Password[i],""); i++;}
  203. }
  204.